package net.hzlj.platform.enterprise.helper;

import android.content.Context;
import android.widget.Toast;

/**
 * @ClassName: ToastHelper
 * @Description: Toast 工具类
 * @Author: Jason.Zhang zhangyujn1989ok@gmail.com
 * @Date: 2016-1-8 14:16:40
 */
public class ToastHelper {

    private static ToastHelper toastHelper = new ToastHelper();

    private static Toast toast;


    public synchronized static ToastHelper newInstance() {
        return toastHelper;
    }

    private ToastHelper() {

    }

    public void show(Context context, String message) {
        if (toast == null) {
            toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
        } else {
            toast.setText(message);
            toast.setDuration(Toast.LENGTH_SHORT);
        }
        toast.show();
    }

    public void show(Context context, int resource) {
        if (toast == null) {
            toast = Toast.makeText(context, context.getString(resource), Toast.LENGTH_SHORT);
        } else {
            toast.setText(context.getString(resource));
            toast.setDuration(Toast.LENGTH_SHORT);
        }
        toast.show();
    }
}
